import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/business/productOrder/list',
  save='/business/productOrder/add',
  edit='/business/productOrder/edit',
  deleteOne = '/business/productOrder/delete',
  deleteBatch = '/business/productOrder/deleteBatch',
  importExcel = '/business/productOrder/importExcel',
  exportXls = '/business/productOrder/exportXls',
  busProductionPlanInformationList = '/business/productOrder/queryBusProductOrderMaterialByMainId',
  busProductionPlanProcessTableList = '/business/productOrder/queryBusProductOrderProcessByMainId',
  approved = '/business/productOrder/approved',
  unApproved = '/business/productOrder/unApproved',
  unCancelWorkOrder = '/business/productOrder/cancelWorkOrder',
  transfer =  '/business/productOrder/transfer',
  getBomListByMaterialId = '/base/materialBom/list',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/** 
 * 查询子表数据
 * @param params
 */
export const busProductionPlanInformationList = Api.busProductionPlanInformationList;
/**
 * 查询子表数据
 * @param params
 */
export const busProductionPlanProcessTableList = Api.busProductionPlanProcessTableList;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});
// 根据料品id 查BOM列表
export const getBomListByMaterialId = (params) =>
  defHttp.get({ url: Api.getBomListByMaterialId, params });

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 审核
 * @param params
 */
export const approvedItem = (params,handleSuccess) => {
  return defHttp.post({url: Api.approved, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 取审
 * @param params
 */
export const unApprovedItem = (params,handleSuccess) => {
  return defHttp.post({url: Api.unApproved, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
export const unCancelWorkOrderItem = (params) => {
  return defHttp.post({url: Api.unCancelWorkOrder, params}, {joinParamsToUrl: true}).then(() => {
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

export const saveTransfer = (params, isUpdate) => {
  // let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: Api.transfer, params});
}